import Vue from "vue";
import VueRouter from "vue-router";
import NProgress from "nprogress";
import { getToken } from "@/utils/token";
import { routerPage } from "@/router/common.router";

Vue.use(VueRouter);

const route = new VueRouter({
  mode: "history",
  routes: routerPage
});

NProgress.configure({ showSpinner: false });

// route.beforeEach((to, from, next) => {
//   NProgress.start();
//   const token = getToken();
//   // debugger
//   if (token || to.path === "/user/login") {
//     NProgress.start();
//     next();
//   } else {
//     next("/user/login");
//   }
// });

//解决路由地址重复点击的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
export default route;
